package com.ylb.rent.config;

import com.ijpay.alipay.AliPayApiConfig;
import com.ijpay.alipay.AliPayApiConfigKit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @AUTHOR:游李滨
 * @DATE:2023/6/30 16:09
 */

@Configuration
public class PayConfig {


    @Autowired
    AliPayConfigBean aliPayConfigBean;

    @Bean
    AliPayConfigBean aliPayConfig(){
        AliPayApiConfig aliPayApiConfig = AliPayApiConfig.builder()
                .setAppId(aliPayConfigBean.appId)
                .setCharset("UTF-8")
                .setPrivateKey(aliPayConfigBean.privateKey)
                .setAliPayPublicKey(aliPayConfigBean.publicKey)
                .setServiceUrl(aliPayConfigBean.serverUrl)
                .setSignType("RSA2")
                // 普通公钥方式
                .build();

        AliPayApiConfigKit.setThreadLocalAppId(aliPayConfigBean.appId); // 2.1.2 之后的版本，可以不用单独设置
        AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig);

        return aliPayConfigBean;
    }
}
